package com.aquarium.ui;

import java.util.HashMap;
import java.util.Observable;
import java.util.Observer;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.hardware.SensorEvent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.aquarium.R;
import com.aquarium.alarm.AlarmManager;
import com.aquarium.bt.BTManager;
import com.aquarium.module.ModuleControlService;
import com.aquarium.sensor.SensorManager;
import com.aquarium.sensor.SensorValueView;

public class SensorValueDisplayActivity extends Activity implements Observer {

	private static final String TAG = "SensorValueDisplayActivity";

	public final static int HANDLE_UPDATE_SENSOR_VALUE = 1;
	public final static int HANDLE_UPDATE_SENSOR_ALARM_VALUE = 2;
	public final static int HANLE_REQUEST_SENSOR_VALUE = 3;
	public final static int HANLE_REQUST_SENSOR_VALUE_TIMEOUT = 4;
	public final static int HANLE_REQUST_SENSOR_VALUE_SUCCESS = 5;

	private SensorManager mSensorManager;
	private AlarmManager mAlarmManager;
	private BTManager mBTManager;
	private float mCurrentPhValue;
	private float mCurrentTemperatureValue;
	private float mCurrentOxygenValue;
	private float mCurrentConductivityValue;
	private float mCurrentWaterLevelValue;
	private HashMap<String, String> mSensorValueMap;

	private Resources mResources;
	private Context mContext;

	private float mPhMin;
	private float mPhMax;
	private float mTemperatureMin;
	private float mTemperatureMax;
	private float mOxygenMin;
	private float mOxygenMax;
	private float mConductivityMin;
	private float mConductivityMax;
	private float mWaterLevelMin;
	private float mWaterLevelMax;

	private View mPHValueView;
	private View mTempValueView;
	private View mOxygenValueView;
	private View mConductivityValueView;
	private View mWaterLevelValueView;

	private TextView mPHValueTextView;
	private TextView mPHValueMinTextView;
	private TextView mPHValueCurrentTextView;
	private TextView mPHValueMaxTextView;
	private TextView mTempValueTextView;
	private TextView mTempValueMinTextView;
	private TextView mTempValueCurrentTextView;
	private TextView mTempValueMaxTextView;
	private TextView mOxygenValueTextView;
	private TextView mOxygenValueMinTextView;
	private TextView mOxygenValueCurrentTextView;
	private TextView mOxygenValueMaxTextView;
	private TextView mConductivityValueTextView;
	private TextView mConductivityValueMinTextView;
	private TextView mConductivityValueCurrentTextView;
	private TextView mConductivityValueMaxTextView;
	private TextView mWaterLevelValueTextView;
	private TextView mWaterLevelValueMinTextView;
	private TextView mWaterLevelValueCurrentTextView;
	private TextView mWaterLevelValueMaxTextView;

	private ImageView mPHValueImageView;
	private ImageView mTempValueImageView;
	private ImageView mOxygenValueImageView;
	private ImageView mConductivityValueImageView;
	private ImageView mWaterLevelValueImageView;

	// private ProgressBar mPHValueProgressBar;
	// private ProgressBar mTempValueProgressBar;
	// private ProgressBar mOxygenValueProgressBar;
	// private ProgressBar mConductivityValueProgressBar;
	// private ProgressBar mWaterLevelValueProgressBar;

	private SensorValueView mPHSensorValueView;
	private SensorValueView mTempSensorValueView;
	private SensorValueView mOxygenSensorValueView;
	private SensorValueView mConductivitySensorValueView;
	private SensorValueView mWaterLevelSensorValueView;

	private ImageButton mHistoryDataButton;
	private ImageButton mSettingButton;
	private ImageButton mRefreshButton;

	private ProgressDialog progressDialog;

	private Handler mUiHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case HANDLE_UPDATE_SENSOR_VALUE:
				displayCurrentValue();
				break;
			case HANDLE_UPDATE_SENSOR_ALARM_VALUE:
				displayAlarmValue();
				break;
			case HANLE_REQUEST_SENSOR_VALUE:
				progressDialog = new ProgressDialog(
						SensorValueDisplayActivity.this);
				progressDialog.setCancelable(false);
				progressDialog.setMessage(getString(R.string.please_wait));
				progressDialog.setMessage(getResources().getString(
						R.string.please_wait));
				progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
				progressDialog.show();
				mSensorManager.refreshSensorValue();
				mUiHandler.sendEmptyMessageDelayed(
						HANLE_REQUST_SENSOR_VALUE_TIMEOUT, 3000);
				break;
			case HANLE_REQUST_SENSOR_VALUE_TIMEOUT:
				if (progressDialog != null) {
					progressDialog.dismiss();
				}
				mSensorManager.cancelRefreshSensorValue();
				Toast.makeText(mContext, R.string.receive_data_timeout,
						Toast.LENGTH_SHORT).show();
				break;
			case HANLE_REQUST_SENSOR_VALUE_SUCCESS:
				Log.e(TAG, "get message: sensor value success.");
				if (progressDialog != null) {
					progressDialog.dismiss();
				}
				if (mUiHandler.hasMessages(HANLE_REQUST_SENSOR_VALUE_TIMEOUT)) {
					mUiHandler
							.removeMessages(HANLE_REQUST_SENSOR_VALUE_TIMEOUT);
					Toast.makeText(mContext, R.string.receive_data_success,
							Toast.LENGTH_SHORT).show();
				}
				break;
			default:
				break;
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.sensor_value_display);

		mContext = getApplicationContext();

		// TODO get latest value or default value and display them.
		// TODO we don't know when we got the value.

		mResources = getResources();
		Intent intent = new Intent();
		intent.setClass(SensorValueDisplayActivity.this, AlarmService.class);
		startService(intent);

		Intent moduleControlIntent = new Intent();
		moduleControlIntent.setClass(this, ModuleControlService.class);
		startService(moduleControlIntent);

		mSensorManager = SensorManager.getInstance();
		mSensorManager.addObserver(this);
		mSensorManager.setUiHandler(mUiHandler);
		mAlarmManager = AlarmManager.getInstance(this);
		mAlarmManager.addObserver(this);

		mBTManager = BTManager.getInstance();
		mBTManager.init(mContext);
		findViews();
		setListener();

		// for test
		// final BTManager btManager = BTManager.getInstance();
		// btManager.init(this);
		// btManager.open();
		// btManager.startDiscovery();
		// Timer timer = new Timer();
		// timer.schedule(new TimerTask() {
		//
		// @Override
		// public void run() {
		// btManager.sendData("123".getBytes());
		// }
		// }, 5000, 2000);
	}

	private void updateAlarmValue() {
		mPhMax = mAlarmManager.getPhMax();
		mPhMin = mAlarmManager.getPhMin();
		mTemperatureMax = mAlarmManager.getTemperatureMax();
		mTemperatureMin = mAlarmManager.getTemperatureMin();
		mOxygenMax = mAlarmManager.getOxygenMax();
		mOxygenMin = mAlarmManager.getOxygenMin();
		mConductivityMax = mAlarmManager.getConductivityMax();
		mConductivityMin = mAlarmManager.getConductivityMin();
		mWaterLevelMax = mAlarmManager.getWaterLevelMax();
		mWaterLevelMin = mAlarmManager.getWaterLevelMin();
	}

	@Override
	protected void onResume() {
		super.onResume();
		// test code
		// Log.d(TAG, "start send sensor value test");
		// mBTManager.sendSensorValueTest();
		// mSensorManager.notifySensorValueTest();

		// when activity resume, we need update alarm value manually.
		updateAlarmValue();
		displayAlarmValue();
	}

	@Override
	protected void onPause() {
		super.onPause();
		// mBTManager.stopSendSensorValueTest();
		// mSensorManager.stopNotifySensorValueTest();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Log.e(TAG, "back: exit?");

			AlertDialog.Builder builder = new AlertDialog.Builder(
					SensorValueDisplayActivity.this);
			builder.setMessage(getString(R.string.exit_confirm))
					.setPositiveButton(getText(R.string.ok),
							new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									mBTManager.close();
									stopService(new Intent(
											getApplicationContext(),
											AlarmService.class));
									stopService(new Intent(
											getApplicationContext(),
											ModuleControlService.class));
									System.exit(0);
								}
							})
					.setNegativeButton(getText(R.string.cancel),
							new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									// TODO Auto-generated method stub

								}
							});
			builder.create().show();
		}

		return true;

	}

	@Override
	public void update(Observable observable, Object data) {
		if (observable instanceof SensorManager) {
			mSensorValueMap = (HashMap<String, String>) data;
			mCurrentPhValue = Float.parseFloat(mSensorValueMap
					.get(SensorManager.PH_VALUE_KEY));
			mCurrentTemperatureValue = Float.parseFloat(mSensorValueMap
					.get(SensorManager.TEMPERATURE_VALUE_KEY));
			mCurrentOxygenValue = Float.parseFloat(mSensorValueMap
					.get(SensorManager.OXYGEN_VALUE_KEY));
			mCurrentConductivityValue = Float.parseFloat(mSensorValueMap
					.get(SensorManager.CONDUCTIVITY_VALUE_KEY));
			mCurrentWaterLevelValue = Float.valueOf(mSensorValueMap
					.get(SensorManager.WATER_LEVEL_VALUE_KEY));

			mUiHandler.sendEmptyMessage(HANDLE_UPDATE_SENSOR_VALUE);
			// displayCurrentValue();
		} else if (observable instanceof AlarmManager) {
			HashMap<String, String> map = (HashMap<String, String>) data;
			// TODO find an more efficient way to get value.
			if (map.containsKey(AlarmManager.GET_PH_MIN_KEY)) {
				mPhMin = Float.parseFloat(map.get(AlarmManager.GET_PH_MIN_KEY));
			} else if (map.containsKey(AlarmManager.GET_PH_MAX_KEY)) {
				mPhMax = Float.parseFloat(map.get(AlarmManager.GET_PH_MAX_KEY));
			} else if (map.containsKey(AlarmManager.GET_PH_MAX_KEY)) {
				mTemperatureMin = Float.parseFloat(map
						.get(AlarmManager.GET_TEMPERATURE_MIN_KEY));
			} else if (map.containsKey(AlarmManager.GET_PH_MAX_KEY)) {
				mTemperatureMax = Float.parseFloat(map
						.get(AlarmManager.GET_TEMPERATURE_MAX_KEY));
			} else if (map.containsKey(AlarmManager.GET_OXYGEN_MIN_KEY)) {
				mOxygenMin = Float.parseFloat(map
						.get(AlarmManager.GET_OXYGEN_MIN_KEY));
			} else if (map.containsKey(AlarmManager.GET_OXYGEN_MAX_KEY)) {
				mOxygenMax = Float.parseFloat(map
						.get(AlarmManager.GET_OXYGEN_MAX_KEY));
			} else if (map.containsKey(AlarmManager.GET_CONDUCTIVITY_MIN_KEY)) {
				mConductivityMin = Float.parseFloat(map
						.get(AlarmManager.GET_CONDUCTIVITY_MIN_KEY));
			} else if (map.containsKey(AlarmManager.GET_CONDUCTIVITY_MAX_KEY)) {
				mConductivityMax = Float.parseFloat(map
						.get(AlarmManager.GET_CONDUCTIVITY_MAX_KEY));
			} else if (map.containsKey(AlarmManager.GET_WATER_LEVEL_MIN_KEY)) {
				mWaterLevelMin = Float.parseFloat(map
						.get(AlarmManager.GET_WATER_LEVEL_MIN_KEY));
			} else if (map.containsKey(AlarmManager.GET_WATER_LEVEL_MAX_KEY)) {
				mWaterLevelMax = Float.parseFloat(map
						.get(AlarmManager.GET_WATER_LEVEL_MAX_KEY));
			}

			mUiHandler.sendEmptyMessage(HANDLE_UPDATE_SENSOR_ALARM_VALUE);
		}
	}

	private void setListener() {

		mHistoryDataButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(SensorValueDisplayActivity.this,
						HistoryActivity.class);
				startActivity(intent);
			}
		});

		mSettingButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent();

				intent.setClass(SensorValueDisplayActivity.this,
						MainSettingActivity.class);
				startActivity(intent);

			}
		});

		mRefreshButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				mUiHandler.sendEmptyMessage(HANLE_REQUEST_SENSOR_VALUE);
			}
		});
	}

	private void findViews() {
		mHistoryDataButton = (ImageButton) findViewById(R.id.history_button);
		mSettingButton = (ImageButton) findViewById(R.id.setting_button);
		mRefreshButton = (ImageButton) findViewById(R.id.refresh_button);

		mPHValueView = findViewById(R.id.ph_layout);
		mTempValueView = findViewById(R.id.temperature_layout);
		mOxygenValueView = findViewById(R.id.oxygen_layout);
		mConductivityValueView = findViewById(R.id.conductivity_layout);
		mWaterLevelValueView = findViewById(R.id.waterLevel_layout);

		mPHSensorValueView = (SensorValueView) mPHValueView
				.findViewById(R.id.sensor_value_view);
		mTempSensorValueView = (SensorValueView) mTempValueView
				.findViewById(R.id.sensor_value_view);
		mOxygenSensorValueView = (SensorValueView) mOxygenValueView
				.findViewById(R.id.sensor_value_view);
		mConductivitySensorValueView = (SensorValueView) mConductivityValueView
				.findViewById(R.id.sensor_value_view);
		mWaterLevelSensorValueView = (SensorValueView) mWaterLevelValueView
				.findViewById(R.id.sensor_value_view);

		mPHValueImageView = (ImageView) mPHValueView
				.findViewById(R.id.sensor_icon);
		mPHValueTextView = (TextView) mPHValueView
				.findViewById(R.id.sensor_value);
		mPHValueMinTextView = (TextView) mPHValueView
				.findViewById(R.id.sensor_value_min);
		mPHValueCurrentTextView = (TextView) mPHValueView
				.findViewById(R.id.sensor_value_current);
		mPHValueMaxTextView = (TextView) mPHValueView
				.findViewById(R.id.sensor_value_max);
		// mPHValueProgressBar = (ProgressBar) mPHValueView
		// .findViewById(R.id.sensor_progress);

		mTempValueImageView = (ImageView) mTempValueView
				.findViewById(R.id.sensor_icon);
		mTempValueTextView = (TextView) mTempValueView
				.findViewById(R.id.sensor_value);
		mTempValueMinTextView = (TextView) mTempValueView
				.findViewById(R.id.sensor_value_min);
		mTempValueCurrentTextView = (TextView) mTempValueView
				.findViewById(R.id.sensor_value_current);
		mTempValueMaxTextView = (TextView) mTempValueView
				.findViewById(R.id.sensor_value_max);
		// mTempValueProgressBar = (ProgressBar) mTempValueView
		// .findViewById(R.id.sensor_progress);

		mOxygenValueImageView = (ImageView) mOxygenValueView
				.findViewById(R.id.sensor_icon);
		mOxygenValueTextView = (TextView) mOxygenValueView
				.findViewById(R.id.sensor_value);
		mOxygenValueMinTextView = (TextView) mOxygenValueView
				.findViewById(R.id.sensor_value_min);
		mOxygenValueCurrentTextView = (TextView) mOxygenValueView
				.findViewById(R.id.sensor_value_current);
		mOxygenValueMaxTextView = (TextView) mOxygenValueView
				.findViewById(R.id.sensor_value_max);
		// mOxygenValueProgressBar = (ProgressBar) mOxygenValueView
		// .findViewById(R.id.sensor_progress);

		mConductivityValueImageView = (ImageView) mConductivityValueView
				.findViewById(R.id.sensor_icon);
		mConductivityValueTextView = (TextView) mConductivityValueView
				.findViewById(R.id.sensor_value);
		mConductivityValueMinTextView = (TextView) mConductivityValueView
				.findViewById(R.id.sensor_value_min);
		mConductivityValueCurrentTextView = (TextView) mConductivityValueView
				.findViewById(R.id.sensor_value_current);
		mConductivityValueMaxTextView = (TextView) mConductivityValueView
				.findViewById(R.id.sensor_value_max);
		// mConductivityValueProgressBar = (ProgressBar) mConductivityValueView
		// .findViewById(R.id.sensor_progress);

		mWaterLevelValueImageView = (ImageView) mWaterLevelValueView
				.findViewById(R.id.sensor_icon);
		mWaterLevelValueTextView = (TextView) mWaterLevelValueView
				.findViewById(R.id.sensor_value);
		mWaterLevelValueMinTextView = (TextView) mWaterLevelValueView
				.findViewById(R.id.sensor_value_min);
		mWaterLevelValueCurrentTextView = (TextView) mWaterLevelValueView
				.findViewById(R.id.sensor_value_current);
		mWaterLevelValueMaxTextView = (TextView) mWaterLevelValueView
				.findViewById(R.id.sensor_value_max);
		// mWaterLevelValueProgressBar = (ProgressBar) mWaterLevelValueView
		// .findViewById(R.id.sensor_progress);

		mPHValueImageView.setImageResource(R.drawable.ph);
		// mPHValueImageView.setBackgroundResource(R.drawable.ph);
		mTempValueImageView.setImageResource(R.drawable.temperature);
		mOxygenValueImageView.setImageResource(R.drawable.redox);
		mConductivityValueImageView.setImageResource(R.drawable.conductivity);
		mWaterLevelValueImageView.setImageResource(R.drawable.water_level);

		mPHValueTextView.setText(R.string.ph_value);
		mTempValueTextView.setText(R.string.temperature_value);
		mOxygenValueTextView.setText(R.string.oxygen_value);
		mConductivityValueTextView.setText(R.string.conductivity_value);
		mWaterLevelValueTextView.setText(R.string.waterLevel_value);
	}

	/**
	 * refresh current value on screen.
	 */
	private void displayCurrentValue() {
		mPHValueCurrentTextView.setText(Float.toString(mCurrentPhValue));
		mTempValueCurrentTextView.setText(Float
				.toString(mCurrentTemperatureValue));
		mOxygenValueCurrentTextView
				.setText(Float.toString(mCurrentOxygenValue));
		mConductivityValueCurrentTextView.setText(Float
				.toString(mCurrentConductivityValue));
		mWaterLevelValueCurrentTextView.setText(Float
				.toString(mCurrentWaterLevelValue));

		updateValueColor();
	}

	/**
	 * refresh alarm value on screen.
	 */
	private void displayAlarmValue() {
		mPHValueMinTextView.setText(Float.toString(mPhMin));
		mPHValueMaxTextView.setText(Float.toString(mPhMax));
		mTempValueMinTextView.setText(Float.toString(mTemperatureMin));
		mTempValueMaxTextView.setText(Float.toString(mTemperatureMax));
		mOxygenValueMinTextView.setText(Float.toString(mOxygenMin));
		mOxygenValueMaxTextView.setText(Float.toString(mOxygenMax));
		mConductivityValueMinTextView.setText(Float.toString(mConductivityMin));
		mConductivityValueMaxTextView.setText(Float.toString(mConductivityMax));
		mWaterLevelValueMinTextView.setText(Float.toString(mWaterLevelMin));
		mWaterLevelValueMaxTextView.setText(Float.toString(mWaterLevelMax));

		updateValueColor();
	}

	/**
	 * change the color of current value to indicate security.
	 */
	private void updateValueColor() {
		if (mCurrentPhValue > mPhMin && mCurrentPhValue < mPhMax) {
			mPHValueCurrentTextView.setTextColor(Color.GREEN);
			// mPHValueProgressBar.setProgressDrawable(mResources
			// .getDrawable(R.drawable.progressbar_bg_normal));
			// mPHValueProgressBar.setProgress((int) ((mCurrentPhValue - mPhMin)
			// / (mPhMax - mPhMin) * 100));
		} else {
			mPHValueCurrentTextView.setTextColor(Color.RED);
			// mPHValueProgressBar.setProgressDrawable(mResources
			// .getDrawable(R.drawable.progressbar_bg_abnormal));
			// mPHValueProgressBar.setProgress(0);
		}

		if (mCurrentTemperatureValue > mTemperatureMin
				&& mCurrentTemperatureValue < mTemperatureMax) {
			mTempValueCurrentTextView.setTextColor(Color.GREEN);
			// mTempValueProgressBar.setProgressDrawable(mResources
			// .getDrawable(R.drawable.progressbar_bg_normal));
			// mTempValueProgressBar
			// .setProgress((int) ((mCurrentTemperatureValue - mTemperatureMin)
			// / (mTemperatureMax - mTemperatureMin) * 100));
		} else {
			mTempValueCurrentTextView.setTextColor(Color.RED);
			// mTempValueProgressBar.setProgressDrawable(mResources
			// .getDrawable(R.drawable.progressbar_bg_abnormal));
			// mTempValueProgressBar.setProgress(0);
		}

		if (mCurrentOxygenValue > mOxygenMin
				&& mCurrentOxygenValue < mOxygenMax) {
			mOxygenValueCurrentTextView.setTextColor(Color.GREEN);
			// mOxygenValueProgressBar.setProgressDrawable(mResources
			// .getDrawable(R.drawable.progressbar_bg_normal));
			// mOxygenValueProgressBar
			// .setProgress((int) ((mCurrentOxygenValue - mOxygenMin)
			// / (mOxygenMax - mOxygenMin) * 100));
		} else {
			mOxygenValueCurrentTextView.setTextColor(Color.RED);
			// mOxygenValueProgressBar.setProgressDrawable(mResources
			// .getDrawable(R.drawable.progressbar_bg_abnormal));
			// mOxygenValueProgressBar.setProgress(0);
		}

		if (mCurrentConductivityValue > mConductivityMin
				&& mCurrentConductivityValue < mConductivityMax) {
			mConductivityValueCurrentTextView.setTextColor(Color.GREEN);
			// mConductivityValueProgressBar.setProgressDrawable(mResources
			// .getDrawable(R.drawable.progressbar_bg_normal));
			// mConductivityValueProgressBar
			// .setProgress((int) ((mCurrentConductivityValue -
			// mConductivityMin)
			// / (mConductivityMax - mConductivityMin) * 100));
		} else {
			mConductivityValueCurrentTextView.setTextColor(Color.RED);
			// mConductivityValueProgressBar.setProgressDrawable(mResources
			// .getDrawable(R.drawable.progressbar_bg_abnormal));
			// mConductivityValueProgressBar.setProgress(0);
		}

		if (mCurrentWaterLevelValue > mWaterLevelMin
				&& mCurrentWaterLevelValue < mWaterLevelMax) {
			mWaterLevelValueCurrentTextView.setTextColor(Color.GREEN);
			// mWaterLevelValueProgressBar.setProgressDrawable(mResources
			// .getDrawable(R.drawable.progressbar_bg_normal));
			// mWaterLevelValueProgressBar
			// .setProgress((int) ((mCurrentWaterLevelValue - mWaterLevelMin)
			// / (mWaterLevelMax - mWaterLevelMin) * 100));
		} else {
			mWaterLevelValueCurrentTextView.setTextColor(Color.RED);
			// mWaterLevelValueProgressBar.setProgressDrawable(mResources
			// .getDrawable(R.drawable.progressbar_bg_abnormal));
			// mWaterLevelValueProgressBar.setProgress(0);
		}

		mPHSensorValueView.setCurrentValue(mCurrentPhValue, mPhMin, mPhMax);
		mTempSensorValueView.setCurrentValue(mCurrentTemperatureValue,
				mTemperatureMin, mTemperatureMax);
		mOxygenSensorValueView.setCurrentValue(mCurrentOxygenValue, mOxygenMin,
				mOxygenMax);
		mConductivitySensorValueView.setCurrentValue(mCurrentConductivityValue,
				mConductivityMin, mConductivityMax);
		;
		mWaterLevelSensorValueView.setCurrentValue(mCurrentWaterLevelValue,
				mWaterLevelMin, mWaterLevelMax);
	}

}
